package org.tio.sitexxx.web.server.controller.gl;

import com.jfinal.plugin.activerecord.Page;
import org.tio.http.server.annotation.RequestPath;
import org.tio.sitexxx.service.model.main.Retail;
import org.tio.sitexxx.service.service.gl.RetailManageService;
import org.tio.utils.crypto.Md5;
import org.tio.utils.resp.Resp;

/**
 * 商户管理
 */
@RequestPath("/gl/manage/retail")
public class RetailManage {

    public RetailManageService retailManageService = RetailManageService.me;

    /**
     * 商户列表
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @RequestPath("/list")
    public Resp retailList(int pageNumber,int pageSize){
        Page<Retail> retailPage = retailManageService.RetailList(pageNumber,pageSize);
        if(retailPage==null||retailPage.getList().size()==0)
            return Resp.fail();
        return Resp.ok(retailPage);
    }

    /**
     * 修改密码
     * @param id
     * @param password
     * @return
     */
    @RequestPath("/update/password")
    public Resp updatePassword(int id,String password){
        boolean result = Retail.dao.findById(id).set("password", Md5.getMD5(password)).update();
        if(!result)
            return Resp.fail();
        return Resp.ok();
    }

}
